<script src="/layui/layui.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css" media="all">
<script src="/src/style/prism.js"></script>
<link href="/src/style/prism.css" rel="stylesheet" />
<style>
    .layui-layer-undefined  .layui-layer-content{
        overflow: auto;
    }
</style>

<div class="layui-fluid">
    <div class="layui-card layui-card-body">

        <div class="layui-form" lay-filter="LAY-app-form2">
            <div class="layui-form-item">

                <div class="layui-inline ">
                    <label class="layui-form-label">监听用户:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="user" placeholder="" value="<?php echo $info['user']; ?>">
                    </div>
                </div>
                <div class="layui-inline ">
                    <label class="layui-form-label">监听所有:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="all" placeholder="" value="<?php echo $info['all']; ?>">
                    </div>
                </div>
                <div class="layui-inline ">
                    <label class="layui-form-label">监听操作:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="action" placeholder="" value="<?php echo $info['action']; ?>">
                    </div>
                </div>
                <div class="layui-inline ">
                    <label class="layui-form-label">不监听操作:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="notaction" placeholder="" value="<?php echo $info['notaction']; ?>">
                    </div>
                </div>
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-submit2" >提交</button>
            </div>


        </div>

        <div class="layui-form" lay-filter="app-content-list">
            <div class="layui-form-item">

            </div>
            <div class="layui-form-item">

                <div class="layui-inline ">
                    <label class="layui-form-label">用户中文名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="user" placeholder="">
                    </div>
                </div>

                <div class="layui-inline ">
                    <label class="layui-form-label">操作名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="action" placeholder="如:orderlist">
                    </div>
                </div>

                <div class="layui-inline ">
                    <label class="layui-form-label">搜索内容</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="data" placeholder="">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <select name="type">
                            <option value="">全部</option>
                            <option value="500">错误</option>
                            <option value="1">正常</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">操作时间</label>
                    <div class="layui-input-inline layui-jy-datetime" style="width: 290px">
                        <input type="text" class="layui-input" id="date" name="ctime" placeholder="">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label"> </label>
                    <button class="layui-btn layuiadmin-btn-list search" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
            <div class="layui-inline ">
                当前日志总条数 <?php echo $count; ?>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
        </div>
    </div>
</div>
<script type="text/html" id="operation">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
</script>
<script>
    layui.use(['form', 'table','laydate'], function(){
        var $ = layui.$
            ,view = layui.view
            ,table = layui.table
            ,form = layui.form
            ,laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
            ,range: true
        });
        table.render({
            elem: "#LAY-app-content-list"
            ,url:'/index/Log/index'
            ,autoSort: false
            ,method: 'post'
            ,cols: [[
                {field: "id",title: "ID",align: "center",'sort':true},
                {field: "time",title: "耗时",align: "center",'sort':true},
                {field: "user",title: "用户",align: "center"},
                {field: "type",title: "状态",align: "center"},
                {field: "module",title: "模块",align: "center"},
                {field: "controller",title: "控制器",align: "center"},
                {field: "action",title: "操作名",align: "center"},
                {field: "ctime",title: "操作时间",align: "center",'sort':true},
                {title: "操作", width: 90, align: "center", fixed: "right", toolbar: "#operation"}
            ]]
            ,page: true
            ,limit: 30
            ,limits: [10, 15, 20, 25, 30,60,100]
            ,text: "系统繁忙,请稍后再试！"
        })
        var fieldOrder='';
        form.render(null, 'app-content-list');
        table.on('sort(LAY-app-content-list)', function(obj){
            fieldOrder=obj;
            $(".search").click();
        })
        //监听行内 操作
        table.on('tool(LAY-app-content-list)', function (obj) {
            switch (obj.event) {
                case 'detail':
                    var html='<pre><code class="line-numbers language-json" id="pre">';
                    html+='</code></pre>';
                    layer.open({
                        type: 5,
                        title: '内容',
                        shade: [0.5, '#000'],
                        offset: '10px',
                        area: ["95%","95%"],
                        shadeClose: true,
                        closeBtn: 1,
                        anim: 2,
                        content: html,
                        cancel:function () {

                        }
                    });
                    var h=JSON.stringify(JSON.parse(obj.data.data),null,4);
                    if(h.indexOf('<div>')==-1){
                        h=h.replace(/\\n/g, " ");
                        h=h.replace(/\\r/g, " ");
                        h=h.replace(/\\\\\\/g, "");
                        h = h.replace(/\\\\u/g, "%u");
                        // h=h.replace(/\\"/g, '"');
                        $("#pre").html(unescape(h));
                    }else{
                        $("#pre").text(h);
                    }
                    Prism.highlightAll();

                    break;
            }
            ;
        });
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            if(fieldOrder){
                field.orderField=fieldOrder.field;
                field.orderType=fieldOrder.type;
            }
            table.reload('LAY-app-content-list', {
                where: field,
                initSort:fieldOrder,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
        form.on('submit(LAY-app-submit2)', function(data){
            var field = data.field;
            ajax(field,'/index/Log/config');
            return false;
        })
        function ajax(field,url) {
            $.ajax({
                type: "POST",
                url: url,
                dataType: 'json',
                data: field,
                success: function (data) {
                    layer.closeAll();
                    $('.search').click();
                    if(typeof data.data=="undefined"){
                        var res={};
                    }else{
                        var res=data.data;
                    }
                    if(data.code==1){
                        if(typeof res.url!="undefined"){
                            window.location.href= data.data.url;
                        }else{
                            layer.alert(data.msg);
                        }
                    }else{
                        layer.alert(data.msg);
                    }
                },
                error: function () {
                    $('.search').click();
                    layer.closeAll();
                    alert('系统繁忙,请稍后再试!');
                },
                beforeSend: function () {
                    layer.load(2, {
                        shade: [0.01, '#fff']
                    });
                }
            });
        }
    });


</script>



